﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Licenta1.Statements;

namespace Licenta1.Expressions
{
    class FunctionExpression:Expression
    {
        Expression p, id;

        public FunctionExpression(Context con, Expression id, Expression p_)
            : base(con)
        {
            p = p_;
            this.id = id;
        }

        public override object Value
        {
            get
            {
                UserFunction uf = null;
                foreach (UserFunction u in context.userFunctions)
                    if ( u.name == ((IdentifierExpression)id).Name)
                    {
                        uf = u;
                        break;
                    }
                if (uf != null)
                {
                    FunctionExecution fe = new FunctionExecution(uf, p);
                    return fe.Value();
                }
                else return null;
            }
        }
    }
}
